I have a column that I've converted from DXL to text. Object o for o in current Module do { if (o."DXL for setIsLegacy" == "True") { o."isLegacy" = "True" } }// end for o in current Module tlwtheq - Thu Jun 16 12:31:23 EDT 2011 |
Re: What's wrong with this picture? a) Use that as the right side of an assignment: ... S = o."DXL for setIsLegacy" b) Concatenate it with a string: ... o."DXL for setIsLegacy" "" So that line becomes: if (o."DXL for setIsLegacy" "" == "True") Now it indeed says that is sub-section "Concatenation (attribute)" and "Assignment (from attribute)", and if you read each and every word of the manual and remember exactly what was said, you will (of course) notice that it does NOT say anything about comparing an "attrRef" with a string, as in <o.NameAttr == "S">. That means you cannot do it. OK, is usually means you cannot do it but I digress. I can say without hesitation that 99% of all DXL programers have done what you did since the DXL manual is rather confusing, even if it is indeed technically correct.
Now some nit-picks: As for your code, I notice that when "setLegacy" is false that you leave "isLegacy" alone, which means it could have retained a true value. I notice that your question suggests taht "isLegacy" is an attribute of type Boolean. If so, this may work better: o."isLegacy" = true You should also please avoid using the word "Column" and in this case surely you mean "Attribute" or "Object Attribute" or "Object Attribute Value". A "Column" is something you see in a view, and while it usually contains a specific "Attribute" it can contain other things. Perhaps your first two lines really are: I had a Layout Column that I converted to an Attr-DXL of type Text. I want to copy that text attribute to a boolean attribute for all objects. |
Re: What's wrong with this picture? llandale - Thu Jun 16 13:25:59 EDT 2011
Now some nit-picks: As for your code, I notice that when "setLegacy" is false that you leave "isLegacy" alone, which means it could have retained a true value. I notice that your question suggests taht "isLegacy" is an attribute of type Boolean. If so, this may work better: o."isLegacy" = true You should also please avoid using the word "Column" and in this case surely you mean "Attribute" or "Object Attribute" or "Object Attribute Value". A "Column" is something you see in a view, and while it usually contains a specific "Attribute" it can contain other things. Perhaps your first two lines really are: I had a Layout Column that I converted to an Attr-DXL of type Text. I want to copy that text attribute to a boolean attribute for all objects. Object o for o in current Module do { if (o."DXL for setIsLegacy" "" == "True") { o."isLegacy" = "true" } }// end for o in current Module |
Re: What's wrong with this picture? tlwtheq - Thu Jun 16 13:32:10 EDT 2011 |
Re: What's wrong with this picture? tlwtheq - Thu Jun 16 13:36:27 EDT 2011 before the if statement. Then it worked. Go figure. string isDxlLegacyAttr = "" Object o for o in current Module do { isDxlLegacyAttr = o."DXL for setIsLegacy" "" print "DXL legacy attribute is set to " isDxlLegacyAttr "\n" if (isDxlLegacyAttr == "True") { o."isLegacy" = "true" } }// end for o in current Module |
Re: What's wrong with this picture? |
Re: What's wrong with this picture? tlwtheq - Thu Jun 16 13:51:55 EDT 2011 |
Re: What's wrong with this picture? llandale - Thu Jun 16 15:06:03 EDT 2011 string isDxlLegacyAttr = "" Object o for o in current Module do { isDxlLegacyAttr = o."DXL for setIsLegacy" "" if (isDxlLegacyAttr == "True") { o."isLegacy" = "true" } }// end for o in current Module After: string isDxlLegacyAttr = "" Object o for o in current Module do { isDxlLegacyAttr = o."DXL for setIsLegacy" "" print "DXL legacy attribute is set to " isDxlLegacyAttr "\n" if (isDxlLegacyAttr == "True") { o."isLegacy" = "true" } }// end for o in current Module One little print statement can be a big thing. |
Re: What's wrong with this picture? tlwtheq - Fri Jun 17 08:11:32 EDT 2011 string isDxlLegacyAttr = "" Object o for o in current Module do { isDxlLegacyAttr = o."DXL for setIsLegacy" "" if (isDxlLegacyAttr == "True") { o."isLegacy" = "true" } }// end for o in current Module After: string isDxlLegacyAttr = "" Object o for o in current Module do { isDxlLegacyAttr = o."DXL for setIsLegacy" "" print "DXL legacy attribute is set to " isDxlLegacyAttr "\n" if (isDxlLegacyAttr == "True") { o."isLegacy" = "true" } }// end for o in current Module One little print statement can be a big thing. <1> Get rid of the empty line after your "if" statement. If that line is not perfectly empty then its not 'empty' and that line will be the subject of the implied "then" statement, and the bracket block following will always execute. <2> I'm guessing the "paste" into the Browser is converting some of your invisible characters, typically EOLs and leading spaces. Perhaps some of your End-Of-Line's are not actual EOLs, but rather Carridge-Returns CRs or Line-Feeds LFs. Put your cursor at the end of each line, <del> which should bring the next line up, then hit ENTER to move it back down. Copy the first code from the browser of your post and try to run it.
|